package com.itheima.recursion;

public class RecursionDemo {
    public static void main(String[] args) {
        System.gc();
        Long start = System.currentTimeMillis();
        int sum = getSum(5000);
        System.out.println("sum = " + sum);
        Long end = System.currentTimeMillis();
        System.out.println("耗时" + (end - start));
        System.gc();
        start = System.currentTimeMillis();
        System.out.println("sum =" + getSums(500000));
        end = System.currentTimeMillis();
        System.out.println("耗时" + (end - start));
    }

    private static int getSum(int i) {
        if (i == 1){
            return 1;
        }else
            return i + getSum(i-1);
    }

    private static int getSums(int i) {
        int sum = 0;
        for (int j = 1; j <= i; j++) {
            sum += j;
        }
        return sum;
    }
}
